﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadGridCommandArgument.aspx.cs" Inherits="Simple.RadGridSortAndPaging.Views.RadGridCommandArgument" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .RadGrid .ReadCommand {
            cursor: pointer;
            width: 16px;
            height: 16px;
            line-height: 16px;
            display: inline-block;
            border: 0;
            background: transparent url("/Images/read.png") 0 -1px no-repeat;
        }

        .RadGrid span.ReadCommand {
            background-position: 0 0;
        }

        .RadGrid .ReadCommand:hover {
            background-position: 0 -5px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </asp:ScriptManager>
        <%--<telerik:RadScriptManager ID="RadScriptManager2" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>--%>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>
        <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1"></telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"></telerik:RadAjaxManager>
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="200px" Width="300px">
            <telerik:RadGrid ID="RadGrid1" runat="server"
                AllowPaging="True"
                AllowSorting="True"
                AllowCustomPaging="True"
                AllowAutomaticDeletes="False"
                AllowAutomaticInserts="False"
                AllowAutomaticUpdates="False"
                Culture="zh-TW" Width="100%"
                GroupPanelPosition="Top"
                GroupingEnabled="False"
                EnableHeaderContextMenu="True"
                AutoGenerateDeleteColumn="False"
                AutoGenerateEditColumn="False"
                OnNeedDataSource="RadGrid1_NeedDataSource"
                OnItemCommand="RadGrid1_ItemCommand"
                OnItemCreated="RadGrid1_ItemCreated"
                AllowMultiRowSelection="false"
                GridLines="None"
                ItemType="Simple.RadGridSortAndPaging.Models.Orders">

                <MasterTableView
                    CommandItemDisplay="TopAndBottom"
                    AllowSorting="True"
                    EditMode="PopUp"
                    AllowFilteringByColumn="True"
                    DataKeyNames="OrderID"
                    ClientDataKeyNames="OrderID"
                    ItemType="Simple.RadGridSortAndPaging.Models.Orders"
                    AutoGenerateColumns="False">
                    <CommandItemSettings ShowExportToExcelButton="True" AddNewRecordText="新增" ShowAddNewRecordButton="true"></CommandItemSettings>
                    <EditFormSettings>
                        <EditColumn UniqueName="EditCommandColumn1" ButtonType="ImageButton" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
                    </EditFormSettings>
                    <NoRecordsTemplate>
                        找不到資料！！
                    </NoRecordsTemplate>

                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>

                    <Columns>

                        <telerik:GridTemplateColumn AllowFiltering="false" AllowSorting="false">
                            <HeaderStyle Width="2%"></HeaderStyle>
                            <ItemStyle CssClass="tac" />
                            <ItemTemplate>
                                <telerik:RadButton ID="ReadRecord_RadButton" runat="server"
                                    ToolTip="讀取"
                                    CssClass="ReadCommand"
                                    CommandName="ReadCommand"
                                    OnClientClicking="ReadCommand"
                                    CommandArgument='<%# Item.OrderID +","+ Item.CustomerID %>'>
                                    <Image EnableImageButton="true" />
                                </telerik:RadButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>

                        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Edit" Text="Edit" HeaderText="" UniqueName="Edit">
                        </telerik:GridButtonColumn>

                        <%--    <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID">
                        </telerik:GridBoundColumn>--%>

                        <telerik:GridTemplateColumn HeaderText="OrderID" UniqueName="OrderID"
                            DataField="OrderID" SortExpression="OrderID">
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text="<%# BindItem.OrderID %>"></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text="<%# BindItem.OrderID %>"></asp:Label>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>

                        <telerik:GridBoundColumn DataField="CustomerID" AutoPostBackOnFilter="True" FilterControlAltText="Filter CustomerID column" HeaderText="CustomerID" SortExpression="CustomerID" UniqueName="CustomerID">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text=""></ModelErrorMessage>
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID11" SortExpression="CustomerID" UniqueName="CustomerID11"
                            CurrentFilterFunction="Contains" AutoPostBackOnFilter="True" ShowFilterIcon="true" FilterDelay="2600" FilterControlAltText="Filter CustomerID column">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text=""></ModelErrorMessage>
                            </ColumnValidationSettings>
                            <HeaderStyle HorizontalAlign="Center" Width="70px"></HeaderStyle>
                            <ItemStyle HorizontalAlign="Center" />
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Freight" FilterControlAltText="Filter Freight column" HeaderText="Freight" SortExpression="Freight" UniqueName="Freight">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text=""></ModelErrorMessage>
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="ShipName" FilterControlAltText="Filter ShipName column" HeaderText="ShipName" SortExpression="AdditionalContactInfo" UniqueName="ShipName">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text=""></ModelErrorMessage>
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="ShipAddress" FilterControlAltText="Filter ShipAddress column" HeaderText="ShipAddress" SortExpression="ShipAddress" UniqueName="ShipAddress">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text=""></ModelErrorMessage>
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="ShipCity" FilterControlAltText="Filter ShipCity column" HeaderText="ShipCity" SortExpression="ShipCity" UniqueName="ShipCity">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text=""></ModelErrorMessage>
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="ShipRegion" FilterControlAltText="Filter ShipRegion column" HeaderText="ShipRegion" SortExpression="ShipRegion" UniqueName="ShipRegion">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text=""></ModelErrorMessage>
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="ShipCountry" FilterControlAltText="Filter ShipCountry column" HeaderText="ShipCountry" SortExpression="ShipCountry" UniqueName="ShipCountry">
                            <ColumnValidationSettings>
                                <ModelErrorMessage Text=""></ModelErrorMessage>
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>

                        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Delete" HeaderText="" UniqueName="Delete" />
                    </Columns>
                </MasterTableView>

                <HeaderContextMenu EnableTheming="True">
                    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                </HeaderContextMenu>
                <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                <GroupingSettings CaseSensitive="False" />
                <FilterMenu EnableTheming="False">
                    <CollapseAnimation Type="OutSine" Duration="200"></CollapseAnimation>
                </FilterMenu>
                <ExportSettings ExportOnlyData="True" OpenInNewWindow="True">
                    <Excel Format="ExcelML"></Excel>
                </ExportSettings>
                <ClientSettings EnableRowHoverStyle="true">
                    <Selecting AllowRowSelect="True"></Selecting>
                </ClientSettings>
            </telerik:RadGrid>
        </telerik:RadAjaxPanel>
    </form>

    <script type="text/javascript">
        <%--function Read(sender, args, index) {
            var grid = $find("<%= RadGrid1.ClientID %>");
            var MasterTable = grid.get_masterTableView();
            var row = MasterTable.get_dataItems()[index];
            var orderId = MasterTable.getCellByColumnUniqueName(row, "OrderID"); //Access the bound column
            var msg = String.format("確定讀取：{0}?", orderId);
            RadControlOfConfirmation(sender, args, msg, "提示");
        }--%>

        function Read(index) {
            var grid = $find("<%= RadGrid1.ClientID %>");
            var MasterTable = grid.get_masterTableView();
            var row = MasterTable.get_dataItems()[index];
            var orderid = MasterTable.getCellByColumnUniqueName(row, "OrderID").innerHTML;
            var orderId = $find("<%=RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[index].getDataKeyValue("OrderID");
            var msg = String.format("確定讀取：{0}?", orderId);
            alert(msg);
            return false;
        }

        function GetSelectOrderId() {

            var grid = $find("<%= RadGrid1.ClientID %>");
            var gridSelectedItems = grid.get_selectedItems();
            var masterTableView = grid.get_masterTableView();
            var orderId = masterTableView.get_selectedItems()[0].getDataKeyValue("OrderID");
            var orderid = masterTableView.getCellByColumnUniqueName(masterTableView.get_selectedItems()[0], "OrderID").innerHTML;
            console.log(orderid);
            console.log(orderId);
            return orderId;
        }
        function ReadCommand(sender, args) {
            //var orderid = GetSelectOrderId();
            var orderId = args._commandArgument;
            var msg = String.format("確定讀取：{0}?", orderId);
            RadControlOfConfirmation(sender, args, msg, "提示");
        }

        function RadControlOfConfirmation(sender, args, msg, title, width, height) {
            var callBack = Function.createDelegate(sender,
                function (shouldSubmit) {
                    if (shouldSubmit) {
                        //this.set_autoPostBack(true);
                        this.click();
                    } else {
                        //this.set_autoPostBack(false);
                        //__doPostBack(sender.name, "");
                    }
                });
            if (msg === undefined) {
                msg = "您確定要?";
            }
            if (title === undefined) {
                title = "確認視窗";
            }
            if (width === undefined) {
                width = 300;
            }
            if (height === undefined) {
                height = 210;
            }
            radconfirm(msg, callBack, width, height, null, title);

            args.set_cancel(true);
        }
    </script>
</body>
</html>